﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Xml.Linq;
using System.Collections.Generic;

namespace ProjectMadaktariMVC.Models
{
    public class ProcedureDAO
    {
        private static MadaktariDataContext db = DBFactory.DB;

        //Query Methods

        /// <summary>
        /// Returns all Procedures in the System
        /// </summary>
        /// <returns></returns>
        public List<Procedure> FindAllProcedures()
        {
            return db.Procedures.ToList<Procedure>();
        }

        /// <summary>
        /// Returns a Procedure with the given id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Procedure GetProcedure(int id)
        {
            return db.Procedures.Single<Procedure>(d => d.procedureID == id);
        }

        //Insert/Delete Methods

        /// <summary>
        /// Adds a new Procedure into the system.  Save() must be called for this change to be persisted
        /// </summary>
        /// <param name="procedure"></param>
        public void Add(Procedure procedure)
        {
            db.Procedures.InsertOnSubmit(procedure);
        }

        /// <summary>
        /// Removes a Procedure from the system. Save() must be called for this change to be persisted
        /// </summary>
        /// <param name="procedure"></param>
        public void Delete(Procedure procedure)
        {
            db.Procedures.DeleteOnSubmit(procedure);
        }

        //Save Method

        /// <summary>
        /// Saves all changes in the model to the database.
        /// </summary>
        public void Save()
        {
            db.SubmitChanges();
        }
    }
}
